<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
<!--      <el-form-item label="开始时间" prop="startDate">-->
<!--        <el-date-picker-->
<!--          clearable-->
<!--          v-model="queryParams.startDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择开始时间"-->
<!--        >-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="结束时间" prop="endDate">-->
<!--        <el-date-picker-->
<!--          clearable-->
<!--          v-model="queryParams.endDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择结束时间"-->
<!--        >-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item label="所属军区" prop="theirMilitary">
        <el-select
          v-model="queryParams.theirMilitary"
          placeholder="请选择所属军区"
          @change="handleQuery"
        >
          <el-option
            v-for="dict in belong_military_region"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="门店" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="门店"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="老师" prop="teacherName">
        <el-input
          v-model="queryParams.teacherName"
          placeholder="老师"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>



<!--      <el-form-item label="用户类型">-->
<!--        <el-select @change="handleQuery" v-model="queryParams.queryUser" placeholder="请选择">-->
<!--          <el-option label="所有" value="1"></el-option>-->
<!--          <el-option label="销售" value="2"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="分享人昵称" prop="shareNickName" label-width="100">-->
<!--        <el-input-->
<!--          v-model="queryParams.shareNickName"-->
<!--          placeholder="分享人昵称"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

<!--      <el-form-item label="项目" prop="project">-->
<!--        <el-select-->
<!--          @change="handleQuery"-->
<!--          v-model="queryParams.project"-->
<!--          placeholder="选择分类"-->
<!--          clearable-->
<!--          style="width: 240px"-->
<!--        >-->
<!--          <el-option label="万里牛要货" value="万里牛要货"/>-->
<!--          <el-option label="万里牛退货" value="万里牛退货"/>-->
<!--          <el-option label="博卡开单" value="博卡开单"/>-->
<!--          <el-option label="博卡退款" value="博卡退款"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->


      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
        >导出
        </el-button>
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <right-toolbar-->
    <!--        v-model:showSearch="showSearch"-->
    <!--        @queryTable="getList"-->
    <!--      ></right-toolbar>-->
    <!--    </el-row>-->

    <el-table
      v-loading="loading"
      :data="hairTriggerEventList"
    >
      <el-table-column label="军区" align="center" prop="theirMilitary"/>
      <el-table-column label="门店" align="center" prop="shopName"/>
      <el-table-column label="老师" align="center" prop="teacherName"/>
      <el-table-column label="作品数" align="center" prop="photoNum"/>
      <el-table-column label="自我介绍" align="center" prop="selfIntroduction"/>
      <el-table-column label="评论数" align="center" prop="commentNum"/>
<!--      <el-table-column label="成本"  align="center" prop="receivable"/>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary"  @click="handleParticulars(scope.row,'/gallantry/hairFixTeacherPhoto')">查看作品</el-button>
          <el-button link type="primary"  @click="handleParticulars(scope.row,'/gallantry/hairFixTeacherIntroduction')">查看自我介绍</el-button>
          <el-button link type="primary"  @click="handleParticulars(scope.row,'/gallantry/hairTeacherEvaluate')">查看评论</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="HairTriggerEvent">
import {
  getTeacherMaterialList
} from "@/api/business/operation";
import {useRoute, useRouter} from "vue-router";
const router = useRouter();
const route = useRoute()
const {proxy} = getCurrentInstance();
const { sys_teacher_tag, belong_military_region } = proxy.useDict(
  "sys_teacher_tag",
  "belong_military_region"
);
const hairTriggerEventList = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const today  = new Date();
const dateRange = ref([proxy.parseTime(new Date(), "{y}-{m}-{d}") + ' 00:00:00', proxy.parseTime(new Date(), "{y}-{m}-{d}") + ' 23:59:59']);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 15,
    theirMilitary: "济南军区",
    teacherName:  route.query != undefined ? route.query?.teacherName : undefined,
    startDate:  route.query?.startDate != undefined ? route.query?.startDate : proxy.parseTime(new Date(today.getFullYear(),today.getMonth(),1), "{y}-{m}-{d}"),
    endDate: route.query?.endDate != undefined ? route.query?.endDate : proxy.parseTime(new Date(), "{y}-{m}-{d}"),
    nickName: undefined,
    // queryUser: "1",
    salesDirector: undefined,
    eventValue: undefined,
  },
});

const {queryParams, form, rules} = toRefs(data);

/** 查询用户触发事件记录列表 */
function getList() {
  loading.value = true;
  getTeacherMaterialList(queryParams.value).then((response) => {
    hairTriggerEventList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
function handleParticulars(row,url){
  router.push({
    path: url,
    query: {
      teacherId: row.teacherId
    },
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  queryParams.value = {
    pageNum: 1,
    pageSize: 15,
    userId: null,
    type: null,
    theirMilitary: null,
    startDate: null,
    endDate: null,
    nickName: null,
    salesDirector: null,
    eventValue: null,
  };
  handleQuery();
}


/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "business/operation/exportTeacherMaterialList",
    {
      ...queryParams.value,
    },
    `accountStatement_${new Date().getTime()}.xlsx`
  );
}

getList();
</script>
